package cn.lysj.framework.api.controller;

import cn.lysj.framework.api.base.ApiContent;
import cn.lysj.framework.common.utils.web.ParamUtil;
import cn.lysj.framework.common.utils.web.Resp;
import cn.lysj.framework.customer.domain.Customer;
import cn.lysj.framework.store.domain.UserFeedback;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ Author ：drj.
 * @ Date  ：Created in 15:14 2018/11/13
 * @ Description:
 **/
@RestController
@RequestMapping("/api/v1/user")
@Api(value = "ApiUserFeedbackController", tags = "用户反馈模块")
public class ApiUserFeedbackController extends ApiContent {

    @PostMapping("/user_feedback")
    public Resp userFeedback(String customerId,String storeId,String message){
        if(ParamUtil.isBlank(customerId)){
            return new Resp(Resp.NO_LOGIN,"用户信息有误!");
        }
        Customer customer = customerService.findOne(customerId);
        if(customer == null){
            return new Resp(Resp.NO_LOGIN,"用户信息有误!");
        }
        if(ParamUtil.isBlank(storeId)){
            return new Resp(Resp.PARAM_ERROR,"未获取到门店信息!");
        }
        if(ParamUtil.isBlank(message)){
            return new Resp(Resp.PARAM_ERROR,"请输入反馈信息!");
        }
        UserFeedback userFeedback = new UserFeedback();
        userFeedback.setStoreId(storeId);
        userFeedback.setCustomerId(customerId);
        userFeedback.setMessage(message);
        userFeedback.setReadFlag(1);
        userFeedbackRepository.save(userFeedback);
        return new Resp("提交反馈成功!");
    }

    @GetMapping("/get_feedback")
    public Resp getFeedback(String customerId,String storeId){
        if(ParamUtil.isBlank(customerId)){
            return new Resp(Resp.NO_LOGIN,"用户信息有误!");
        }
        Customer customer = customerService.findOne(customerId);
        if(customer == null){
            return new Resp(Resp.NO_LOGIN,"用户信息有误!");
        }
        return new Resp(userFeedbackRepository.findByCustomerIdAndStoreIdOrderByCreateTimeDesc(customerId,storeId));
    }



}
